package com.quasar.hpatient.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.model.medicalmodel.DiagnosisData;

/**
 * 事件列表
 */
public class WidgetEvent extends LinearLayout {

    private Drawable icons;

    public WidgetEvent(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public WidgetEvent(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.widget_event, this);
        event_note = (TextView) findViewById(R.id.event_note);
        event_icon = (ImageView) findViewById(R.id.event_icon);
        event_del = (TextView) findViewById(R.id.event_del);
    }

    TextView event_note,event_del;
    ImageView event_icon;
    private DiagnosisData diagnosisData;

    public DiagnosisData getDiagnosisData() {
        return diagnosisData;
    }

    public void setDiagnosisData(DiagnosisData diagnosisData) {
        this.diagnosisData = diagnosisData;
    }

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.widget_event, this);
        event_note = (TextView) findViewById(R.id.event_note);
        event_icon = (ImageView) findViewById(R.id.event_icon);
        event_del = (TextView) findViewById(R.id.event_del);

        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.WidgetEvent);

        String event_note_string = a.getString(R.styleable.WidgetEvent_event_note);
        if (event_note_string != null) {
            event_note.setText(event_note_string);
        }
        if (a.hasValue(R.styleable.WidgetEvent_event_icon)) {
            icons = a.getDrawable(
                    R.styleable.WidgetTitle_title_icon);
            icons.setCallback(this);
        }
        a.recycle();
        if (icons != null) {
            event_icon.setImageDrawable(icons);
        }
    }

    public void setText(String t) {
        event_note.setText(t + "");
    }

    public void setIcons(int id){
        event_icon.setImageResource(id);
    }

    public TextView getDelView(){
        return event_del;
    }


    public void isDel(Boolean isdel){
        //是否显示删除按钮
        if(isdel){
            event_del.setVisibility(VISIBLE);
        }else{
            event_del.setVisibility(GONE);
        }
    }
}
